package com.ruoyi.course.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.course.domain.TermCalendarEvents;
import com.ruoyi.course.service.ITermCalendarEventsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学期关键日历事件Controller
 * 
 * @author chenxl
 * @date 2025-08-29
 */
@RestController
@RequestMapping("/course/events")
public class TermCalendarEventsController extends BaseController
{
    @Autowired
    private ITermCalendarEventsService termCalendarEventsService;

    /**
     * 查询学期关键日历事件列表
     */
   // @PreAuthorize("@ss.hasPermi('course:events:list')")
    @GetMapping("/list")
    public TableDataInfo list(TermCalendarEvents termCalendarEvents)
    {
        startPage();
        List<TermCalendarEvents> list = termCalendarEventsService.selectTermCalendarEventsList(termCalendarEvents);
        return getDataTable(list);
    }

    /**
     * 导出学期关键日历事件列表
     */
    @PreAuthorize("@ss.hasPermi('course:events:export')")
    @Log(title = "学期关键日历事件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TermCalendarEvents termCalendarEvents)
    {
        List<TermCalendarEvents> list = termCalendarEventsService.selectTermCalendarEventsList(termCalendarEvents);
        ExcelUtil<TermCalendarEvents> util = new ExcelUtil<TermCalendarEvents>(TermCalendarEvents.class);
        util.exportExcel(response, list, "学期关键日历事件数据");
    }

    /**
     * 获取学期关键日历事件详细信息
     */
    @PreAuthorize("@ss.hasPermi('course:events:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(termCalendarEventsService.selectTermCalendarEventsById(id));
    }

    /**
     * 新增学期关键日历事件
     */
    @PreAuthorize("@ss.hasPermi('course:events:add')")
    @Log(title = "学期关键日历事件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TermCalendarEvents termCalendarEvents)
    {
        return toAjax(termCalendarEventsService.insertTermCalendarEvents(termCalendarEvents));
    }

    /**
     * 修改学期关键日历事件
     */
    @PreAuthorize("@ss.hasPermi('course:events:edit')")
    @Log(title = "学期关键日历事件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TermCalendarEvents termCalendarEvents)
    {
        return toAjax(termCalendarEventsService.updateTermCalendarEvents(termCalendarEvents));
    }

    /**
     * 删除学期关键日历事件
     */
    @PreAuthorize("@ss.hasPermi('course:events:remove')")
    @Log(title = "学期关键日历事件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(termCalendarEventsService.deleteTermCalendarEventsByIds(ids));
    }
}
